home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 101513.2141@compuserve.com (Jean-Marc Delforge)
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Q: '\n' character
- Date: Fri, 05 Apr 1996 09:33:47 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4k2lu3$9oe@dub-news-svc-1.compuserve.com>
- References: <31616F63.481D@lava.weeg.uiowa.edu> <4jtddt$eu7@masala.cc.uh.edu> <DpBuF6.83C@ukpsshp1.serigate.philips.nl>
- NNTP-Posting-Host: hd42-154.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) wrote:
-
- >Spasmo (cosc19z5@Bayou.UH.EDU) wrote:
- >: Artur Wojdat (awojdat@lava.weeg.uiowa.edu) wrote:
- >: : Hello everybody,
- >: : Is there a function or some sort of way that I could remove '\n'
- >: : charecter form the end of the string. I'm reading from two files, want to
- >: Dunno if there are any functions available, but what I always do
- >: is just overwrite the '\n' with a '\0', which does the job nicely.
-
- >: For example, let's say that the string that holds the data is called
- >: buf. To get rid of the '\n' you'd merely do the following:
-
- >: buf[strlen(buf) - 1] = '\0';
-
- >: And that takes care of that.
-
- >Thats the best way, but do check that the character you are about to overwrite
- >is a newline. There are two occasions when fgets stops without reading a
- >newline, first if it has filled your buffer (because you have a very long line
- >in the file), second if there is no newline at the end of the last line of the
- >file.
-
- >--
- >Stephen Baynes baynes@ukpsshp1.serigate.philips.nl
- >Philips Semiconductors Ltd
- >Southampton My views are my own.
- >United Kingdom
-
- Try this
-
- char * ptr;
-
- if ((ptr = strchr (buf, '\n')) != NULL) *ptr = '\0';
-
-
-